package net.taiqin.tqerp.controller.po;

import com.github.pagehelper.PageInfo;
import java.util.List;
import net.taiqin.tqerp.controller.param.po.PurchaseParam;
import net.taiqin.tqerp.domain.common.BaseVO;
import net.taiqin.tqerp.domain.po.POHeaderVO;
import net.taiqin.tqerp.domain.po.POLinesVO;
import net.taiqin.tqerp.domain.po.POMessagesVO;
import net.taiqin.tqerp.domain.po.POReturnLinesVO;
import net.taiqin.tqerp.domain.po.POStatusCountsVO;
import net.taiqin.tqerp.exception.MyException;
import net.taiqin.tqerp.service.po.IPurchaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/po"})
public class PurchaseController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    public IPurchaseService purchaseService;

    @RequestMapping(
            value = {"/findPoStatusCounts"},
            method = {RequestMethod.POST}
    )
    public List<POStatusCountsVO> findPoStatusCounts(@RequestBody PurchaseParam param) {
        this.logger.info("---------------------------------查询PO状态数据-----------------------");
        List<POStatusCountsVO> poStatusCountsVOList = this.purchaseService.findPoStatusCounts(param);
        return poStatusCountsVOList;
    }

    @RequestMapping(
            value = {"/findPOHeaderList"},
            method = {RequestMethod.POST}
    )
    public PageInfo<POHeaderVO> findPOHeaderList(@RequestBody PurchaseParam param) {
        this.logger.info("---------------------------------查询PO状态数据-----------------------");
        PageInfo<POHeaderVO> pageInfo = this.purchaseService.findPOHeaderList(param);
        return pageInfo;
    }

    @RequestMapping(
            value = {"/findPODetailList"},
            method = {RequestMethod.POST}
    )
    public PageInfo<POLinesVO> findPODetailList(@RequestBody PurchaseParam param) {
        this.logger.info("---------------------------------查询PO状态数据-----------------------");
        PageInfo<POLinesVO> pageInfo = this.purchaseService.findPODetailList(param);
        return pageInfo;
    }

    @RequestMapping(
            value = {"/findPOMessages"},
            method = {RequestMethod.POST}
    )
    public PageInfo<POMessagesVO> findPOMessages(@RequestBody PurchaseParam parm) {
        this.logger.info("---------------------------------查询PO Message数据-----------------------");
        PageInfo<POMessagesVO> pageInfo = this.purchaseService.findPOMessages(parm);
        return pageInfo;
    }

    @RequestMapping(
            value = {"/findPOReturnLines"},
            method = {RequestMethod.POST}
    )
    public PageInfo<POReturnLinesVO> findPOReturnLines(@RequestBody PurchaseParam parm) {
        this.logger.info("---------------------------------查询PO 退货单数据-----------------------");
        PageInfo<POReturnLinesVO> pageInfo = this.purchaseService.findPOReturnLines(parm);
        return pageInfo;
    }

    @RequestMapping(
            value = {"/updatePO"},
            method = {RequestMethod.POST}
    )
    public BaseVO updatePO(@RequestBody PurchaseParam param) {
        this.logger.info("---------------------------------更新PO数据-----------------------");
        BaseVO respaonseVO = this.purchaseService.updatePo(param);
        return respaonseVO;
    }

    @RequestMapping({"/json"})
    public String json() throws MyException {
        throw new MyException("发生错误2");
    }

    @RequestMapping({"/json1"})
    public String json1() throws MyException {
        throw new MyException("发生错误1");
    }
}